/**
 * Copyright (c) 2011-11-12 WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.wkm.frame;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.wkm.frame.listener.ButtonActionListener;
import org.wkm.frame.listener.DefaultWindowListener;
import org.wkm.task.file.DataReader;

/**
 * @author WKM
 * Modification history
 * 1.WKM - 2011-11-12 -Create File
 */
public class MessageBox extends JFrame{

	private static DataReader READER = DataReader.getInstance();
	
	public static String DEFAULT_IMAGE_NAME = READER.getProperty("message.frame.icon");
	
	/**
	 * 信息提示框
	 */
	private static final long serialVersionUID = 1L;
	
	private MessageBox(){}
	
	public static void showMessageBox(){
		showMessageBox(READER.getProperty("message.frame.title"),
				READER.getProperty("message.frame.message"));
	}
	
	public static void showMessageBox(String title,String text){
		showMessageBox(title,text,DEFAULT_IMAGE_NAME);
	}
	
	public static void showMessageBox(String title,String text,String imageName){
		MessageBox box = new MessageBox();
		JLabel label = new JLabel();
		JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		JButton button = new JButton(READER.getProperty("system.button.ok"));
		button.addActionListener(new ButtonActionListener(box));
		southPanel.add(button);
		label.setText(text);
		label.setFont(new Font("楷体",Font.BOLD,20));
		box.addWindowListener(new DefaultWindowListener());
		box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		box.setTitle(title);
		box.setSize(300, 100);
		box.setLocationRelativeTo(null);
		box.setLayout(new BorderLayout());
		northPanel.add(label);
		box.add(northPanel,BorderLayout.NORTH);
		box.add(southPanel,BorderLayout.SOUTH);
		box.setIconImage(READER.getImage(imageName));
		box.setResizable(Boolean.FALSE);
		box.setVisible(true);
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MessageBox.showMessageBox();
	}

}
